package com.mycompany.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.mycompany.entity.Number;
import com.mycompany.repository.NumberDao;
import com.mycompany.service.NumberService;
import com.mycompany.unity.NumberUnity;

@Service
public class NumberServiceImpl implements NumberService {
	
	@Autowired
	private NumberDao numberDao;

	@Override
	@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
	public void persist(Number number) {
		numberDao.persist(number);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
	public void merge(Number number) {
		numberDao.merge(number);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
	public void remove(Number number) {
		numberDao.remove(number);
	}

	@Override
	public Number findById(Integer numberId) {
		return numberDao.findById(numberId);
	}

	@Override
	public Number find(Number number) {
		return numberDao.find(number);
	}

	@Override
	public List<Number> findAll() {
		return numberDao.findAll();
	}
	@Override
	public List<Number> findAllTop10() {
		return numberDao.findAllTop10();
	}

	@Override
	public List<Number> findListByCodition(Number number) {
		return numberDao.findListByCodition(number);
	}
	
	@Override
	public Map<String,Map<String,Integer>> numberSummary(List<Number> numberAll) {

		// *******  Sorting **** 
		Map<String,Map<String,Integer>> mapNumber = NumberUnity.sortingNumber(numberAll);
		return mapNumber;
	}
	
	@Override
	public Map<String,Integer> getNumberSummaryTotal(List<Number> numberAll){
		// *******  Cululate total **** 
		Map<String,Integer> totals = NumberUnity.numberSummaryTotal(numberAll);
		return totals;
	}
	
}
